﻿Imports System.Reflection

Public Class Destrinchador

    Public Shared Sub DestrinchaClasse(ByVal _obj As Object)

        If _obj IsNot Nothing Then

            Console.WriteLine("--> ")
            Dim _assemblyDominio As [Assembly] = [Assembly].GetAssembly(_obj.GetType)
            Dim _tipo As Type = _assemblyDominio.GetType(_obj.GetType.FullName)
            Dim _properties() As PropertyInfo = _tipo.GetProperties()

            Console.WriteLine("{0} : {1}", _tipo.Name, _tipo.FullName)
            For Each _property In _properties
                Dim _propInfo As PropertyInfo = _tipo.GetProperty(_property.Name)
                Dim _object = _propInfo.GetValue(_obj, Nothing)

                If _property.ReflectedType.IsClass AndAlso _property.PropertyType.Name <> "String" AndAlso _object IsNot Nothing AndAlso _assemblyDominio.GetTypes.Contains(_object.GetType) Then
                    'Me.DestrinchaClasse(_object)
                    If _property.PropertyType.IsEnum Then
                        Console.WriteLine("     {0} : {1} = {2}", _property.Name, _property.PropertyType.Name, _object.ToString)
                    Else
                        Console.WriteLine("     {0} : {1} = {2}", _property.Name, _property.PropertyType.Name, "...")
                    End If
                Else
                    If _object IsNot Nothing Then
                        Console.WriteLine("     {0} : {1} = {2}", _property.Name, _property.PropertyType.Name, _object.ToString())
                    Else
                        Console.WriteLine("     {0} : {1} = {2}", _property.Name, _property.PropertyType.Name, "NOTHING")
                    End If
                End If

            Next

        End If

    End Sub

End Class
